# 推导式
# 1. 列表
a = [1 for i in range(11)]
a2 = [x+y for x in 'python' for y in '123']
a3 = [x for x in 'java']
# a2 输出 ['p1', 'p2', 'p3', 'y1', 'y2', 'y3', 't1', 't2', 't3', 'h1', 'h2', 'h3', 'o1', 'o2', 'o3', 'n1', 'n2', 'n3']
# a3 输出 ['j', 'a', 'v', 'a']

a4 = [x for x in 'python' if x!='p']
# 可加条件语句
# a4 输出为 ['y', 't', 'h', 'o', 'n']


# 2. 字典
b = {x:x*2 for x in range(11)}
# b输出 {0: 0, 1: 2, 2: 4, 3: 6, 4: 8, 5: 10, 6: 12, 7: 14, 8: 16, 9: 18, 10: 20}


# 3. 元组
c = tuple(x for x in range(11))
# 必须包含 关键字 tuple
# 输出为 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)



# 三元运算符
# 语法：值1 if 条件 else 值2
f = 3; g = 3
d = f if f > g else g
